package _22define;

import java.io.*;
import java.util.Arrays ;

public class SortAndAppendFile {
    public static void main(String[] args) {

        String original = "rsztuvijxypbmnocklwaefghdq";

        try (FileReader reader = new FileReader("input.txt ")) {
            char[] buffer = new char[1024];
            int count = reader.read (buffer);
            if (count > 0) {
                char[] characters = new char[count];
                System.arraycopy (buffer, 0, characters, 0, count);
                Arrays.sort (characters); // 对字符数组进行排序

                // 将排序后的字符数组写回文件
                try (FileWriter writer = new FileWriter("input.txt ", true)) {
                    writer.write (new String(characters)); // 追加写入
                    writer.write ("\n"); // 换行
                }
            }
        } catch (IOException e) {
            e.printStackTrace ();
        }
    }
}